const express=require("express")
const router=express.Router();
const pool=require("../pool");
//功能品牌车列表
router.get("/brand",(req,res)=>{
  var brand=req.query.brand;    //商品id
  console.log(brand);
  var sql=`SELECT 
          cid,src,title,brand,des,price,tid
          FROM car_type WHERE brand=?`;
  pool.query(sql,[brand],(err,result)=>{
    if(err) throw err;
    console.log(result);
    res.send({code:1,data:result});
  })
})
router.get("/newCarList",(req,res)=>{
 //1:获取参数
   //1:参数 pno pageSize,添加分页查
   var pno=req.query.pno;
   var pageSize=req.query.pageSize;
   //2:允许使用默认值  1 7
   if(!pno){pno=1}
   if(!pageSize){pageSize=5}

   var ps=parseInt(pageSize);
   var offset=(pno-1)*ps;

  var sql=`SELECT 
          cid,src,title,brand,des,price,tid
          FROM car_type
          LIMIT ?,?
          `;
  pool.query(sql,[offset,ps],(err,result)=>{
    if(err) throw err;
    console.log(result);
    res.send({code:1,data:result});
  })
})
router.get("/car",(req,res)=>{
  //1:获取参数
    //1:参数 pno pageSize,添加分页查
    var did=req.query.did;
   var sql=`SELECT 
           cid,src,title,brand,des,price,tid
           FROM car_type
           WHERE cid = ?
           `;
   pool.query(sql,[did],(err,result)=>{
     if(err) throw err;
     res.send({code:1,data:result});
   })
 })
module.exports=router;